<template>
<div class="components-container">
     <div class="header-form">
        <div class="layui-inline">
            <label class="layui-form-label" >逝者姓名</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.RegnameLike" placeholder="请输入火化人员姓名" @keydown.enter.native="btnSearch"></el-input>
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >家属姓名</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.ReghandlernameLike" placeholder="请输入家属姓名" @keydown.enter.native="btnSearch"></el-input>
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >业务编号</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.RegbusnumEquals" placeholder="请输入家属姓名" @keydown.enter.native="btnSearch"></el-input>
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >火化日期</label>
            <el-date-picker v-date v-model="selectData.RegcremationdateGreaterAndEquals" type="date" placeholder="大于此日期" style="width: 200px" @change="btnSearch">
            </el-date-picker>
             <el-date-picker v-date v-model="selectData.RegcremationdateLessAndEquals" type="date" placeholder="小于此日期" style="width: 200px" @change="btnSearch">
            </el-date-picker>
        </div>
        <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
        <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
     </div>
        <div style="margin-bottom:10px;margin-top:20px;">
          <el-button type="primary" :disabled="this.$store.state.isloading || downloadLoading" @click="operate('补打火化证明')">补打火化证明</el-button>
          <el-button type="primary" :disabled="this.$store.state.isloading" @click="exportExcel" style="margin-left:20px;margin-bottom:-10px;">导出Excel</el-button>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :isIndex="true" :pageOrder="pageOrder" :hiddenColumn="false" :hiddenPageOrder="false" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <cre-proof ref="prints"></cre-proof>
       
</div>
</template>

<style  rel="stylesheet/scss" lang="scss" scoped>

</style>
<script>
const REPRINT = "补打火化证明";
const INFO = "详情";
import dataTable from "@/components/Table/DataTable";
import creProof from "./creproofDetail";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
export default {
  name: "creproofSearch",
  mixins: [manage],
  data() {
    return {
      selectData: {
        RegnameLike: null,
        ReghandlernameLike: null,
        RegbusnumEquals: null,
        RegcremationdateGreaterAndEquals: null,
        RegcremationdateLessAndEquals: null
      },
      height: "620",
      downloadLoading:false
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if(this.selectData.RegcremationdateGreaterAndEquals){
        startTime = this.selectData.RegcremationdateGreaterAndEquals.toLocaleDateString();
      }else{
        startTime = '空';
      }
      if(this.selectData.RegcremationdateLessAndEquals){
        endTime = this.selectData.RegcremationdateLessAndEquals.toLocaleDateString();
      }else{
        endTime = '空';
      }
      var header = '火化证明查询' + '(' + startTime + '--' + endTime + ')';
       if (this.dataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataList, header,'火化证明查询');
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        // case INFO:
        //   this.title = "火化证明详情";
        //   this.$refs.prints.open(this.order,this.currentRow.PCMREGID,null,false);
        //   break;
        case REPRINT:
          this.title = "补打火化证明";
          if (this.currentRow)
            this.$refs.prints.open(this.order,this.currentRow.PCMREGID,null,true);
          else alert("尚未选中行");
          break;
        default:
          break;
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetCreproofColumns,
        res => {
          console.log(res.data.content);
          this.headList = res.data.content;
        }
      );
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if (!this.selectData.RegnameLike) {
        Data.RegnameLike = null;
      }
      if (!this.selectData.ReghandlernameLike) {
        Data.ReghandlernameLike = null;
      }
      if (!this.selectData.RegbusnumEquals) {
        Data.RegbusnumEquals = null;
      }
      Data.RegcremationdateGreaterAndEquals = formatDate(
        Data.RegcremationdateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.RegcremationdateLessAndEquals = formatDate(
        Data.RegcremationdateLessAndEquals,
        "yyyyMMdd"
      );

      let data = {
        PageIndex: 1,
        PageSize: 1000,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.QueryCreproof,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        RegnameLike: null,
        ReghandlernameLike: null,
        RegbusnumEquals: null,
        RegcremationdateGreaterAndEquals: null,
        RegcremationdateLessAndEquals: null
      };
      if(this.isshowtime == false){
        this.selectData.RegcremationdateGreaterAndEquals = new Date();
        this.selectData.RegcremationdateGreaterAndEquals.setDate(1);
        this.selectData.RegcremationdateLessAndEquals = new Date();
        var day = new Date();
        var year = day.getFullYear();
        var month = day.getMonth() + 1;
        var d = new Date(year, month, 0);
        var dat = d.getDate();
        this.selectData.RegcremationdateLessAndEquals.setDate(dat);
      }
      this.getData();
    }
  },
  components: {
    dataTable,
    creProof
  },

  created() {
    let data = {};
    apiBase.DoService(
      data,
      apiBase.getApiAdress().Param.GetIsCremationQueryDate,
      res => {
        this.isshowtime = res.data.content;
        if(res.data.content == false){
          this.selectData.RegcremationdateGreaterAndEquals = new Date();
          this.selectData.RegcremationdateGreaterAndEquals.setDate(1);
          this.selectData.RegcremationdateLessAndEquals = new Date();
          var day = new Date();
          var year = day.getFullYear();
          var month = day.getMonth() + 1;
          var d = new Date(year, month, 0);
          var dat = d.getDate();
          this.selectData.RegcremationdateLessAndEquals.setDate(dat);
        }
      }
    )
    
    this.getColumns();
    this.getData();
  }
};
</script>

